package cn.base;

import cn.service.*;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.util.ValueStack;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessEngine;

import javax.annotation.Resource;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by HuangJX on 2017/3/2.
 */
public class BaseAction<T> extends ActionSupport implements ModelDriven<T> {

    @Resource
    protected ProcessEngine processEngine;

    @Resource
    protected  ReplyService replyService;

    @Resource
    protected  TopicService topicService;

    @Resource
    protected RoleService roleService;

    @Resource
    protected DepartmentService departmentService;

    @Resource
    protected UserService userService;

    @Resource
    protected PrivilegeService privilegeService;

    @Resource
    protected ForumService forumService;

    @Resource
    protected  TemplateService templateService;
    @Resource
    protected ProcessService processService;

    @Resource
    protected FlowService flowService;

    @Resource
    protected ApproveInfoService approveInfoService;

    protected T model;

    public BaseAction(){
        //获得实体类型
        ParameterizedType type= (ParameterizedType) this.getClass().getGenericSuperclass();//父类的类型
        Type[] types=type.getActualTypeArguments();
        Class<T> classz= (Class<T>) types[0];
        try {
            model=classz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    public T getModel() {
        return model;
    }
    /**
     * 获得值栈
     */
    protected ValueStack getValueStack() {
        return ActionContext.getContext().getValueStack();
    }

    //初始页
    private int currentPage=1;

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
}
